class Car:
    def __init__(self, make, model, year):
        self.make = make
        self.model = model
        self.year = year
        self.odometer_reading = 0

    def get_descriptive_name(self):
        long_name = f"{self.year} {self.make} {self.model}"
        return long_name.title()

    def read_odometer(self):
        print(f"This car has {self.odometer_reading} miles on it.")

    def update_odometer(self, mileage):
        # 用方法（函数）修改属性值，可自定修改条件
        if mileage > self.odometer_reading:
            self.odometer_reading = mileage
        else:
            print("You can't roll back an oldmeter!")

    def increment_odometer(self, miles):
        if miles > 0:
            self.odometer_reading += miles
        else:
            print("You can't roll back an oldmeter!")

# my_new_car = Car('audi', 'a4', 2019)
# print(my_new_car.get_descriptive_name())
# my_new_car.read_odometer()

# my_new_car.odometer_reading = 23_500 # 直接修改属性值，数字间加入'_'不会影响数字的大小，可用该符号使数字易读
# my_new_car.read_odometer()

# my_new_car.update_odometer(23)
# my_new_car.read_odometer()

# my_new_car.increment_odometer(1)
# my_new_car.read_odometer()

# 在一个模块中存储多个类
class Battery:
    def __init__(self, battery_size=75):
        self.battery_size = battery_size

    def update_battery(self):
        if self.battery_size != 100:
            self.battery_size = 100

    def describe_battery(self):
        print(f"This car has a {self.battery_size}-kWh battery.")

    def get_range(self):
        if self.battery_size == 75:
            range = 260
        elif self.battery_size == 100:
            range = 315
        
        print(f"This car can go about {range} miles on a full charge.")

class ElectricCar(Car): # 继承父类Car

    def __init__(self, make, model, year):
        super().__init__(make, model, year) # super()是一种特殊函数，能让子类调用父类的方法
        
        self.battery_size = 75 # 子类特有属性

        # 类作为属性
        self.battery = Battery()

    def describe_battery(self):
        print(f"This car has a {self.battery_size}-kWh battery.")

    def fill_gas_tank(self): # 重写父类的同名方法
        print("This car doesn't need a gas tank!")
